package com.msb.order.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
@RestController
public class DegradationRuleController {


    private AtomicInteger atomicInteger =new AtomicInteger(1);
    @RequestMapping("/slowRequestRatio")
    public String slowRequestRatio(){
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "熔断降级==慢调用比例";
    }

    @RequestMapping("/errorRatio")
    public String errorRatio(){
        atomicInteger.getAndIncrement();
        log.info("现在的数值：{}",atomicInteger.get() );
        if (atomicInteger.get() % 2 == 0){
            //模拟异常和异常比率
            int i = 1/0;
        //    throw  new RuntimeException("异常比例测试");
        }
        return "熔断降级==异常比例";
    }

    @RequestMapping("/errorCount")
    public String errorCount(){
        atomicInteger.getAndIncrement();
        log.info("现在的数值：{}",atomicInteger.get() );
        if (atomicInteger.get() % 2 == 0){
            //模拟异常和异常比率
            int i = 1/0;
        }
        return "熔断降级==异常数量";
    }

}
